


# =============================================================================================================
# =============================================================================================================

# step 2: 安装系统依赖软件

# 修改yum为国内镜像 === 如下四个repo地址
# 看具体情况，有时候国内镜像不一定完整，这个时候还是要切换回国外地址
# 
# 国内repo 资源地址：如下：
# https://mirrors.aliyun.com/repo/
# 


# 1.替换 镜像地址 CentOS-Base.repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak && \
wget -O /etc/yum.repos.d/CentOS-Base.repo -L https://mirrors.aliyun.com/repo/Centos-7.repo

# 2.替换 镜像地址 epel.repo
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
 
# 清理掉无用的repo
yum clean all && \
yum makecache
yum --enablerepo=base clean metadata


# ====================================================================

# 1. make 安装

# CMake 下载资源：https://github.com/tiandong19860806/CMake/tags
# CMake 下载资源：https://github.com/Kitware/CMake/releases/tag/v3.18.6
  
# 下载cmake二进制安装包
mkdir -p /opt/code/cmake/
wget -O /opt/code/cmake/cmake-3.18.6-Linux-x86_64.tar.gz  -L https://github.com/Kitware/CMake/releases/download/v3.18.6/cmake-3.18.6-Linux-x86_64.tar.gz
# wget -O /opt/code/cmake/cmake-3.12.4-Linux-x86_64.tar.gz  -L https://github.com/Kitware/CMake/releases/download/v3.12.4/cmake-3.12.4-Linux-x86_64.tar.gz

# 解压cmake 二进制文件
tar -zxvf /opt/code/cmake/cmake-3.18.6-Linux-x86_64.tar.gz -C /opt/code/cmake/
# tar -zxvf /opt/code/cmake/cmake-3.12.4-Linux-x86_64.tar.gz -C /opt/code/cmake/
mkdir -p /opt/env/cmake/
cp -rf /opt/code/cmake/cmake-3.18.6-Linux-x86_64/* /opt/env/cmake/
# cp -rf /opt/code/cmake/cmake-3.12.4-Linux-x86_64/* /opt/env/cmake/

# 设置cmake的环境变量, 参考：shell下cat EOF中变量$处理
cat >> /etc/profile  << "EOF"

# add by tiandong, for cmake
export CMAKE_HOME=/opt/env/cmake
export PATH=$PATH:$CMAKE_HOME/bin
EOF

# 生效profile设置
source /etc/profile

# 检查make 配置成功
cmake --version
# cmake version 3.18.6

# =======================================================================================================

# 2. 安装依赖库 -- ceph 需要

yum install -y libffi-devel boost cryptopp-devel fcgi-devel libatomic_op-devel libedit-devel boost-devel fuse-devel libtool libuuid-devel libblkid-devel keyutils-libs-devel cryptopp-devel fcgi-devel libcurl-devel expat-devel gperftools-devel libedit-devel libatomic_ops-devel snappy-devel libaio-devel xfsprogs-devel libudev-devel libcrypto++-dev libcrypto++-utils

yum install -y fuse fuse-devel

# 我好像是执行下面这2句，就能成功构建leveldb等软件
yum install -y gcc gcc-c++ automake && \
yum install -y glibc-static libstdc++-static && \
yum install -y openssl-devel

# 后面构建ceph代码，需要安装的组件
# c++ 快速编译，缓存h头文件提供高速访问，参考：https://www.oschina.net/p/ccache?hmsr=aladdin1e1
# yum list installed | grep ccach
yum install -y ccach

# ============================================

yum install -y wget && \
yum install -y autoconf automake make && \
yum install -y gcc-c++ libtool libedit-devel libatomic_ops-devel && \
yum install -y snappy-devel leveldb-devel libaio-devel boost-devel && \
yum install -y gperftools-devel cryptopp-devel fuse-devel && \
yum install -y libuuid-devel keyutils-libs-devel python-argparse

# 我好像是执行下面这2句，就能成功构建leveldb等软件
yum install -y  gcc gcc-c++ automake && \
yum install -y  glibc-static libstdc++-static

# gcc 需要的类库
yum install -y openssl-devel




# =======================================================================================================

# 2. python3 安装

# 参考：https://www.runoob.com/python3/python3-install.html
#
# 参考：强制删除组件
# rpm -e --nodeps {组件名称}
#  
# python 3.8.1 编译报错 Could not import runpy module 问题
# 原因：./configure --enable-optimizations，configure命令后面带上了--enable-optimizations
# https://blog.90.vc/archives/367
#
# shell下cat EOF中变量$处理
# https://blog.csdn.net/ocean_1991/article/details/103895174
# 
# python 2.x/3.x 同时安装 == windows
# https://www.cnblogs.com/zhengyihan1216/p/6011640.html
# https://www.cnblogs.com/wxy2000/p/12396711.html
# 
# python 2.x/3.x 同时安装 == linux
# https://www.cnblogs.com/zhouwanchun/p/12976998.html
# https://www.cnblogs.com/l5623064/p/8690945.html
# https://jingyan.baidu.com/article/642c9d3435a1e9644a46f739.html
# https://blog.csdn.net/watfe/article/details/52755076
# 
# python 官方教程 == 安装pip
# https://docs.python.org/zh-cn/2.7/installing/index.html
# 

# python 2.x 安装完之后，提示的信息，如下： ----------------begin -----------------------
# 解决办法：
# https://blog.csdn.net/huanle0610/article/details/41174943
# https://www.jianshu.com/p/6be231fc2646
# 
# yum install -y bsddb ncurses
# yum install -y sqlite sqlite-devel bz2
# yum install -y bzip2-devel bsddb gdbm-devel
# yum install -y readline-devel zlib
# 
# Python build finished, but the necessary bits to build these modules were not found:
# _bsddb             _curses            _curses_panel   
# _sqlite3           _tkinter           bsddb185        
# bz2                dbm                dl              
# gdbm               imageop            readline        
# sunaudiodev                                           
# To find the necessary bits, look in setup.py in detect_modules() for the module's name.  
# python 2.x 安装完之后，提示的信息，如下： ----------------end -----------------------                              

# 切记：首先，安装依赖库
yum install -y autoconf automake make && \
yum install -y gcc gcc-c++ && \
yum install -y tcl-devel tk-devel


# 切记：python 3.x 需要的类库如下：
yum install -y zlib zlib-devel && \
yum install -y openssl-devel && \
yum install -y  glibc-static libstdc++-static

# django默认数据库为sqlite3，所以安装
# yum install -y sqlite-devel
 

# 下载python源代码
mkdir -p /opt/soft/python/
# wget -O /opt/soft/python/ -L https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
wget -O /opt/soft/python/ -L https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
# tar -zxvf /opt/soft/python/Python-2.7.18.tgz -C /opt/soft/python/
tar -zxvf /opt/soft/python/Python-3.9.1.tgz -C /opt/soft/python/
# 
# 构建python源代码
# cd /opt/soft/python/Python-2.7.18
cd /opt/soft/python/Python-3.9.1

# mkdir -p /usr/local/python-2.7.18
mkdir -p /usr/local/python-3.9.1
# ./configure
# ./configure --enable-optimizations
# ./configure --prefix=/usr/local/python-2.7.18
./configure --prefix=/usr/local/python-3.9.1
# 或者，当上面configure方法不行时候，用如下命令
# ./configure --enable-shared --enable-loadable-sqlite-extensions -with-zlib
# ./configure --enable-shared --enable-loadable-sqlite-extensions -with-zlib --prefix=/usr/local/python-2.7.18

# 编译源代码
make
# 安装python
make install



# 检查python 是否安装成功
# 如果安装成功，则输出 Python 3.9.1
# 检查python-3.x 版本
cd /usr/local/python-3.9.1/bin/ # 参考上面configure指定的install 目录
python3 --version
# 检查python-2.x 版本
cd /usr/local/python-2.7.18/bin/ # 参考上面configure指定的install 目录
python --version 

# 建立软连接
# 查看已有的python版本
ls -al /usr/lib64 | grep python
# -rwxr-xr-x.  1 root root 1847240 Aug  4  2017 libpython2.7.so.1.0
# drwxr-xr-x. 26 root root   20480 Feb 25  2019 python2.7
ls -al /usr/bin | grep python
# lrwxrwxrwx.  1 root root         7 Feb 25  2019 python -> python2
# lrwxrwxrwx.  1 root root         9 Feb 25  2019 python2 -> python2.7
# -rwxr-xr-x.  1 root root      7136 Aug  4  2017 python2.7
# 建立软连接  /usr/local/bin/
# ln -s /usr/local/python-2.7.18/bin/python2.7   /usr/bin/python2
# ln -s /usr/local/python-2.7.18/bin/python2.7   /usr/bin/python2.7
# ln -s /usr/local/python-3.9.1/bin/python3.9    /usr/bin/python3
# ln -s /usr/local/python-3.9.1/bin/python3.9    /usr/bin/python3.9

# 设置python的环境变量, 参考：shell下cat EOF中变量$处理
# 设置python-2.x
cat >> /etc/profile  << "EOF"

PYTHON_HOME_2_7_18=/usr/local/python-2.7.18
PATH=$PATH:$PYTHON_HOME_2_7_18/bin
CLASSPATH=$CLASSPATH:$PYTHON_HOME_2_7_18/lib
EOF
# 设置python-3.x
cat >> /etc/profile  << "EOF"

PYTHON_HOME_3_9_1=/usr/local/python-3.9.1
PATH=$PATH:$PYTHON_HOME_3_9_1/bin
CLASSPATH=$CLASSPATH:$PYTHON_HOME_3_9_1/lib
EOF


# 生效profile设置
source /etc/profile


# =======================================================================================================

# 2. 安装leveldb-1.20

# 问题：安装leveldb报错，执行命令make 或 make test报错，如下
# out-static/autocompact_test: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by out-static/autocompact_test)
# out-static/autocompact_test: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by out-static/autocompact_test)
# 方法：
# 解决/usr/lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found的问题
#       https://blog.csdn.net/u012811841/article/details/77854581/
#  
# libstdc++.so.6.0.24资源包下载
# https://pkgs.org/download/libstdc++.so.6
# https://centos.pkgs.org/7/centos-x86_64/libstdc++-4.8.5-44.el7.i686.rpm.html
# https://blog.csdn.net/weixin_43227196/article/details/110946066
# 
# root >> strings /usr/lib64/libstdc++.so.6 | grep GLIBC
# root >> strings /usr/lib64/libstdc++.so.6|grep CXXABI
# 
# 方法一，教程：rpm命令常用选项，https://www.cnblogs.com/st-jun/p/7736737.html
# mkdir -p /opt/soft/libstdc++
# rpm -ivh /opt/soft/libstdc++/libstdc++-8.3.1-5.1.el8.i686.rpm
# 
# 方法二，操作如下
# 1.查看已经安装的位置
# find /usr -name libstdc++.so.*
# 2.备份之前的软连接
# mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6_bak
# 3.手动创建软连接
# ln -s /usr/local/gcc/lib64/libstdc++.so.6.0.28     /usr/lib64/libstdc++.so.6
# 4.查看创建后的软连接
# ls -al /usr/lib64/libstdc++.so.6
## lrwxrwxrwx 1 root root 40 Feb 17 21:47 /usr/lib64/libstdc++.so.6 -> /usr/local/gcc/lib64/libstdc++.so.6.0.28


# 我好像是执行下面这2句，就能成功构建leveldb等软件
yum install -y  gcc gcc-c++ automake && \
yum install -y  glibc-static libstdc++-static
# gcc 需要的类库
yum install -y openssl-devel

# 下载leveldb
mkdir -p /opt/code/leveldb/
wget -O /opt/code/leveldb/leveldb-1.20.tar.gz  -L https://github.com/google/leveldb/archive/1.20.tar.gz

# 解压leveldb 二进制文件 
tar -zxvf /opt/code/leveldb/leveldb-1.20.tar.gz -C /opt/code/leveldb/
mkdir -p /opt/env/leveldb/
cp -rf /opt/code/leveldb/leveldb-1.20/* /opt/env/leveldb/

# 构建编译 leveldb
cd /opt/env/leveldb/
make -j2 # -j2 表示make构建每次并行编译两个命令

# 将新编译的动态库链接到原来的动态库
cp /opt/env/leveldb/out-shared/libleveldb.so* /usr/lib64/ && \
# rm /usr/lib64/{libleveldb.so,libleveldb.so.1} && \
mv /usr/lib64/libleveldb.so  /usr/lib64/libleveldb.so.bak
mv /usr/lib64/libleveldb.so.1  /usr/lib64/libleveldb.so.1.bak
ln -s /usr/lib64/libleveldb.so.1.20  /usr/lib64/libleveldb.so && \
ln -s /usr/lib64/libleveldb.so.1.20  /usr/lib64/libleveldb.so.1
# 替换头文件
cp -rf /opt/env/leveldb/include/leveldb/ /usr/include/

# =======================================================================================================

# 3. 安装gcc

# 资源：RPM 离线安装包下载：http://www.rpmfind.net/linux/RPM/index.html
# 参考：RPM 离线安装包安装：yum install -y http://www.rpmfind.net/linux/centos/8-stream/AppStream/aarch64/os/Packages/gcc-8.4.1-1.el8.aarch64.rpm

# 资源：gcc 依赖包镜像：https://gcc.gnu.org/mirrors.html
# 资源：gcc 安装包： http://mirror.hust.edu.cn/gnu/gcc/

# 参考：gcc4.8.5升级到高版本gcc遇到的坑： https://blog.csdn.net/weixin_40085653/article/details/108646987
# 参考：make报错，gcc: gengtype-lex.c: No such file or directory： https://blog.csdn.net/lidan3959/article/details/8872573
# 参考：make 如何加快速度：https://blog.csdn.net/gonghuihuihui/article/details/79091762
# 参考：https://blog.csdn.net/weixin_41010198/article/details/106780572    【推荐】【推荐】】
# 参考：以下为，gcc源代码安装
# 参考：https://www.jianshu.com/p/fc162672fae2
# 参考：https://blog.csdn.net/wangqing_12345/article/details/52484723
# 参考：https://blog.csdn.net/ivanlxf/article/details/19080681
# 参考: https://www.cnblogs.com/wanpengcoder/p/5218583.html
# 参考：https://blog.51cto.com/ayuepm/1382240
# 参考：https://blog.csdn.net/lucboll/article/details/93464729
# 参考：http://codingdict.com/questions/45948    （\--enable-optimizations在编译python时做什么？）
# 参考：https://blog.csdn.net/yaoyutian/article/details/90761619  （gcc 执行make编译报错，原因调查和解决） 【推荐】【推荐】
# 参考：https://www.cnblogs.com/ims-/p/12038531.html
# 高版本gcc导致报错：-V 命令没有。http://www.bubuko.com/infodetail-2532434.html

# 具体安装步骤，参考下面文档
# ./gcc-01-7.5.0-install.sh

# =======================================================================================================
  
# 4. 安装ceph
# 参考：centos 7源码编译安装ceph-v14.0.1教程（待修改）： https://blog.csdn.net/smart9527_zc/article/details/84894749
# 参考：Ceph编译：L版本及其之后的版本：https://www.cnblogs.com/powerrailgun/p/12133107.html
# 参考：L版之后master ceph编译问题总结： https://blog.csdn.net/ygtlovezf/article/details/81333956
# 参考：centos 7.4-aarch64如何编译Ceph： https://www.jianshu.com/p/8857bdb6eead
# 参考：centos7编译Ceph14中g++版本和pthread问题： https://younger.blog.csdn.net/article/details/104885092
# -------------------------------------------------------------------------------------------------------------
# 参考：使用cephadm安装ceph octopus
# https://mp.weixin.qq.com/s?__biz=MzIyMDY2MTE3Mw==&mid=2247486775&idx=1&sn=45a1ea7ffbd699aa5e3b0010f132c6df&chksm=97c9d9eda0be50fbb7bc7f089a2b5509b6eaa7435985c0623edc1f71a9b181b4f1ad71d8e222&mpshare=1&scene=1&srcid=0218WDd1RDTBx2HAF5owj27u&sharer_sharetime=1613651880552&sharer_shareid=dbb98f0bb786b869d56cf7506c079a62&key=24acb6bc41823fb6b91608a64efd08720566592c0809bcaff62d54c44568957fa37f8caf827e2147b0ea6de740b47f46430e6b242a647c663403c076fb8608b64c9f29393fc5f7e2aedaf792045306a9522886602440465882d125185683c8c2a19479f8e8f0d971265d102cac426c38b8cae7d07a1fe238c7864fc6abed5602&ascene=1&uin=MTQwMDE1MDYzOA%3D%3D&devicetype=Windows+Server+2008+R2+x64&version=63000039&lang=zh_CN&exportkey=A%2FvU4dGqKktQW8GoYjQu9x8%3D&pass_ticket=N9Zhi3YjBonVpqitCbMeUCIxnbNlT3H2Vj50shGVtPpsJt9W1Fz5ciwFgdhxnebe&wx_header=0
# https://www.cnblogs.com/imirsh/p/13354648.html

# 下载ceph
mkdir -p /opt/code/ceph/
wget -O /opt/code/ceph/ceph-15.2.8.tar.gz  -L https://download.ceph.com/tarballs/ceph-15.2.8.tar.gz

# 解压ceph
tar -zxvf /opt/code/ceph/ceph-15.2.8.tar.gz -C /opt/code/ceph/
mkdir -p /opt/env/ceph/
cp -rf /opt/code/ceph/ceph-15.2.8/* /opt/env/ceph/

# 构建编译 ceph
cd /opt/env/ceph
# 安装依赖库
./install-deps.sh
  
# 执行脚本，执行构建编译源代码  == TODO
yum install -y git # 下面命令有使用git , 所以需要安装
./do_cmake.sh
# 或执行，./do_cmake.sh -DCMAKE_BUILD_TYPE=RelWithDebInfo
# 
# 等价于，如下命令
# cd /opt/env/ceph
# cmake -DWITH_PYTHON3=3.6 -DWITH_CCACHE=OFF  

# 备注： ./do_cmake报错的问题，问题解决了，可能是./CMakeLists.txt文件的问题；
# 它里面有个和git tag有关的操作，我注释掉，执行构建ceph 成功了
# 成功构建，输出如下：
# [root@CNT7XCEPHD08 ceph]# cmake -DWITH_PYTHON3=3.6 -DWITH_CCACHE=OFF
# -- Found CURL: /usr/lib64/libcurl.so (found version "7.29.0") 
# -- ssl soname: libssl.so.10
# -- crypto soname: libcrypto.so.10
# -- Found Python3: /usr/bin/python3.6 (found suitable exact version "3.6.8") found components:  Interpreter Development 
# -- BUILDING Boost Libraries at j 1
# -- boost (1.72.0 >= 1.67) already in /opt/env/ceph/src/boost
# -- Found Yasm: good -- capable of assembling x86_64
# -- Ceph/.git directory not found, parsing /opt/env/ceph/src/.git_version for CEPH_GIT_VER and CEPH_GIT_NICE_VER
# -- Could not find fmt, will build it
# -- Version: 5.3.1
# -- Build type: RelWithDebInfo
# -- CXX_STANDARD: 17
# -- Configuring done
# -- Generating done
# -- Build files have been written to: /opt/env/ceph


# 如果提示git 路径不存在，则打开编辑./do_cmake.sh文件，注释掉git相关操作命令，因为我们是手动下载的ceph代码，没有git版本
# 修改文件前，先备份一下
cp ./do_cmake.sh ./do_cmake.sh.bak

# -------------------------------------------------------- 报错 -----------begin

# 执行命令 ./do_cmake.sh ，报错如下：
# [root@CNT7XCEPHD08 ceph]# cmake -DWITH_PYTHON3=3.6
# CMake Warning:
#   No source or binary directory provided.  Both will be assumed to be the
#   same as the current working directory, but note that this warning will
#   become a fatal error in future CMake releases.
# 
# -- Building with ccache: /usr/bin/ccache, CCACHE_DIR=
# CMake Error at cmake/modules/CephChecks.cmake:3 (message):
#   GCC 7+ required due to C++17 requirements
# Call Stack (most recent call first):
#   CMakeLists.txt:89 (include)

# 解决办法
 yum install -y centos-release-scl  
 yum install -y devtoolset-7
 scl enable devtoolset-7 bash
 
# 无名氏提供的方法
# ./do_cmake.sh -DWITH_MANPAGE=OFF -DWITH_BABELTRACE=OFF -DWITH_MGR_DASHBOARD_FRONTEND=OFF

# -----------------------------------

# 自动化安装ceph_admin
# https://www.cnblogs.com/imirsh/p/13354648.html

# -----------------------------------

# ./do_cmake报错，如下错误：
# 
# CMake Error at cmake/modules/CTags.cmake:19 (string):
# string sub-command REPLACE requires at least four arguments.
# Call Stack (most recent call first):
# CMakeLists.txt:661 (add_tags)
# CMake Error at cmake/modules/CTags.cmake:22 (string):
#   string sub-command REPLACE requires at least four arguments.
# Call Stack (most recent call first):
#   CMakeLists.txt:661 (add_tags)
#
# 解决办法，如下：
# ./do_cmake报错的问题，问题解决了，可能是./CMakeLists.txt文件的问题；
# 它里面有个和git tag有关的操作如下：行423~430；当我把这几行代码注释掉，则执行构建ceph 成功了。
# include(CTags)
# option(CTAG_EXCLUDES "Exclude files/directories when running ctag.")
# add_tags(ctags
#   SRC_DIR src
#   TAG_FILE tags
#   EXCLUDE_OPTS ${CTAG_EXCLUDES}
#   EXCLUDES "*.js" "*.css")
# add_custom_target(tags DEPENDS ctags)
 
# -------------------------------------------------------- 报错 -----------end


# 执行构建
cd /opt/code/ceph/build
make -j2

# 执行安装
cd /opt/code/ceph/build
make install
 
# =======================================================================================================

# 如果提示缺少三个组件如下，则单独安装一下
# 
# see https://www.softwarecollections.org/en/scls/rhscl/devtoolset-7/ for more details.
# ./install-deps.sh: line 437: virtualenv: command not found
# ./install-deps.sh: line 438: /opt/env/ceph/install-deps-python3/bin/activate: No such file or directory
# ./install-deps.sh: line 425: pip: command not found 
# 
# python 安装pip
# # 安装pip, 和国内python / pip的镜像源  【推荐】【推荐】
# https://www.runoob.com/w3cnote/python-pip-install-usage.html
# https://www.cnblogs.com/luocodes/p/13833037.html  
# https://blog.csdn.net/wickedvalley/article/details/52015878 
# https://www.cnblogs.com/Jimc/p/10218062.html
# https://www.cnblogs.com/Jimc/p/10218387.html


# python升级带来的yum异常：File "/usr/bin/yum", line 30
# yum包管理是使用python2.x写的， 修改yum配置文件，将python版本指向以前的旧版本
# https://blog.csdn.net/z13615480737/article/details/78670228
# https://www.cnblogs.com/grimm/p/11103902.html  
# 操作步骤
# step 1: 复制旧版本python 2.x，如下：
# cp /usr/bin/python2.7_bak_2.7.5  /usr/bin/python2.7
# 
# step 2: 文件1 ： 修改/usr/bin/yum
# vi /usr/bin/yum
# 替换如下内容
# old 内容 = #!/usr/bin/python
# new 内容 = #!/usr/bin/python2.7
# 
# tep 3: 文件2 ： 修改/usr/libexec/urlgrabber-ext-down
# vi /usr/libexec/urlgrabber-ext-down
# 替换如下内容
# old 内容 = #!/usr/bin/python
# new 内容 = #!/usr/bin/python2.7


# python 华为镜像 【推荐】
# https://mirrors.huaweicloud.com/python/
# 
# https://www.runoob.com/w3cnote/python-pip-install-usage.html
# https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/2.0/install/pip/windows-pip.html
# 
# 解决pip使用异常No module named 'pip'
# https://www.cnblogs.com/badaoliumangqizhi/p/11845158.html
# /usr/bin/python: No module named pip
# https://blog.csdn.net/tanmx219/article/details/86748979
# 
# 操作步骤，如下
mkdir -p /opt/code/python
# 或执行如下命令下载
# curl https://bootstrap.pypa.io/get-pip.py -o /opt/code/python/get-pip.py
wget -O /opt/code/python/get-pip.py -L https://bootstrap.pypa.io/get-pip.py

# 运行安装pip, 
# 注意：本地安装哪个版本的 Python，pip 就选择用哪个版本的python命令执行安装。如下分别是python2.x 和 python3.x 安装pip
# 如下是python2.x 和 python3.x 安装pip
# python /opt/code/python/get-pip.py
yum install -y zlib zlib-devel
yum install -y zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
cd /opt/code/python
python2 /opt/code/python/get-pip.py
# 如下是python2.x 和 python3.x 安装pip
python3 /opt/code/python/get-pip.py

#
# python 官方安装教程
# https://docs.python.org/zh-cn/3.8/installing/index.html#install-pip-in-versions-of-python-prior-to-python-3-4
# 
# 查看python安装位置
# root >> which python
# 输出：/usr/bin/python
# 
# 问题：/usr/bin/python: No module named pip
# https://blog.csdn.net/tanmx219/article/details/86748979
# 
# Centos7 安装virtualenv bash: virtualenv: command not found...的解决
# https://www.cnblogs.com/hszstudypy/p/11511228.html
